package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/19 10:27
 * @apiNote
 */

public class Test01047RemoveDuplicates {

    public String removeDuplicates(String s) {
        StringBuffer sb = new StringBuffer();
        int size = -1;
        for(int i = 0;i<s.length();i++){
            char ch = s.charAt(i);
            if(size >= 0 && sb.charAt(size) == ch){
                sb.deleteCharAt(size);
                size--;
            }else{
                sb.append(ch);
                size++;
            }
        }
        return sb.toString();
    }
}
